<?php

class VistaBase {
    /*
     * Asigna variable para ser usada en la vista
     */

    function crearPareja($label, $var, $class = "", $classVar = "") {
        ?>

        <label for="<?php echo $label ?>" class="<?php echo $class ?>" ><?php echo $label ?></label>          
        <label for="<?php echo $var ?>" class="<?php echo $classVar ?>" ><?php echo $var ?></label>

        <?php
    }

    function crearTabla($cabezera, $datos) {
        $c = 0;
        ?>

        <table class="tabla">        
            <thead> 
                <tr >   
                    <?php
                    //$sis= 100/count($cabezera);
                    foreach ($cabezera as $i) {
                        ?>                    
                        <th class="cabe tam"> <? print"$i" ?></th>                     
                    <?php } ?>
                </tr> 
            </thead>
            <?php
            foreach ($datos as $p) {
                $t = $c % 2;
                ?>  
                <tbody>
                    <tr>                        
                        <?php
                        foreach ($p as $v) {
                            if ($t == 0) {
                                ?>
                                <td class="celdaAzul tam">                                
                                    <? print "$v"; ?>
                                </td>   
                            <?php } else { ?> 

                                <td class="celdaGris tam">                                
                                    <? print "$v"; ?>
                                </td>   

                                <?php
                            }
                        }
                        ?> 
                    </tr>
                </tbody>
                <?php
                $c++;
            }
            ?>


        </table>

        <?php
    }

    function crearMenu($lista) {
        ?>       
        <div id="menu">
            <ul class="menu">
                <?php foreach ($lista as $id => $nombre) { ?>


                    <li><a href='<?php echo"?controlador=$id" ?>' class="parent"><span> <?php echo"$nombre" ?></span></a>   
                        <?php
                    }
                    ?>     
                    <?php
                }

                function asignarVariable($variable, $valor) {
                    $this->$variable = $valor;
                }

                /*
                 * Cargar archivo php con html predefinido
                 */

                function cargarTemplate($template) {
                    $template = strtolower($template);
                    $template = 'template/' . $template . '.php';
                    if (file_exists($template)) {
                        require_once $template;
                        return true;
                    } else {
                        return false;
                    }
                }

                /*
                 * Crea input tipo textarea para ser usado en formulario
                 */

                function crearTextarea($label, $name, $value = "", $class_label = "", $class_input = "", $mensaje = "") {
                    ?>
                    <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                    <textarea name="<?php echo $name ?>" id="<?php echo $name ?>" class="input_textarea borde redondeado" placeholder="<?php echo $label ?>"><?php echo $value ?></textarea>
                    <div id="error_<?php echo $name ?>" style="display: none">
                        <?php echo $mensaje ?>
                    </div>
                    <?php
                }

                /*
                 * Crea input tipo text para ser usado en formulario
                 */

                function crearInput($label, $name, $value = "", $class_label = "", $class_input = "", $mensaje = "", $readonly = "") {
                    ?>
                    <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                    <?php if ($readonly == true) { ?>
                        <input type="text" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $value ?>" class="<?php echo $class_input ?>" placeholder="<?php echo $label ?>" readonly="true"/>
                    <?php } else { ?>
                        <input type="text" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $value ?>" class="<?php echo $class_input ?>" placeholder="<?php echo $label ?>"/>
                    <?php } ?>
                    <div id="error_<?php echo $name ?>" style="display: none">
                        <?php echo $mensaje ?>
                    </div>
                    <?php
                }

                /*
                 * Crea input varios tipos id y name individuales para ser usado en formulario--vivi
                 */

                function crearInputId($label, $name, $id, $value = "", $class_label = "", $class_input = "", $mensaje = "", $readonly = "", $tipo = "", $onkeypress = "", $max = "") {
                    ?>

                    <?php if ($readonly == true) { ?>
                        <input type="<?php echo $tipo ?>"  name="<?php echo $name ?>" id="<?php echo $id ?>" value="<?php echo $value ?>" class="input_text borde redondeado <? echo $class_input ?>" placeholder="<?php echo $label ?>"  readonly="true"/>
                    <?php } else { ?>
                        <input type="<?php echo $tipo ?>"  name="<?php echo $name ?>" id="<?php echo $id ?>" value="<?php echo $value ?>" class="input_text borde redondeado <? echo $class_input ?>" placeholder="<?php echo $label ?>" onkeypress= "<?php echo $onkeypress ?>" maxlength="<?php echo $max ?>"/>
                    <?php } ?>
                    <div title="��� Advertencia !!!" id="error_<?php echo $name ?>" style="display: none">
                        <?php echo $mensaje ?>
                    </div>
                    <?php
                }

                function crearInputP($label, $name, $value = "", $class_label = "", $class_input = "", $mensaje = "", $title = "", $pass = "") {
                    ?>
                    <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                    <input type="<?php echo $pass ?>" title="<?php echo $title ?>" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $value ?>" class="<?php echo $class_input ?>" placeholder="<?php echo $label ?>" />
                    <div id="error_<?php echo $name ?>" style="display: none">
                        <?php echo $mensaje ?>
                    </div>
                    <?php
                }

                /*
                 * Crea input tipo text para ser usado en formulario
                 */

                function crearHidden($name, $value = "") {
                    ?>
                    <input type="hidden" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $value ?>" />
                    <?php
                }

                /*
                 * Crea input tipo text para ser usado en formulario
                 */

                function crearToken() {
                    $llave = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                    for ($i = 0; $i < 12; $i++) {
                        $token .= substr($llave, rand(0, 62), 1);
                    }
                    $_SESSION['token'] = $token;
                    ?>
                    <input type="hidden" name="token" id="token" value="<?php echo $token ?>" />
                    <?php
                }

                /*
                 * Crea input tipo text para ser usado en formulario
                 */
                /*
                  function crearCombo($label, $name, $options, $value = "", $class_label = "", $class_input = "") {
                  ?>
                  <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                  <select name="<?php echo $name ?>" id="<?php echo $name ?>" class="<?php echo $class_input ?>">
                  <?php
                  foreach ($options as $valor => $opcion):
                  if ($value == $valor) {
                  $selected = "selected";
                  } else {
                  $selected = "";
                  }
                  ?>
                  <option value="<?php echo $valor ?>" <?php echo $selected ?> ><?php echo $opcion ?></option>
                  <?php endforeach; ?>
                  </select>
                  <div id="error_<?php echo $name ?>"></div>
                  <?php
                  }
                 */

                function crearCombo($label, $name, $options, $value = "", $class_label = "", $class_input = "", $defec = "", $valor = "", $mensaje = "", $disb = "") {
                    if ($defec == true) {
                        $varsun = $valor;
                    } else {
                        $varsun = "";
                    }
                    ?>
                    <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                    <select <?php echo $disb ?> name="<?php echo $name ?>" id="<?php echo $name ?>" class="<?php echo $class_input ?>">                     
                        <?php
                        echo $varsun;
                        foreach ($options as $valor => $opcion):
                            if ($value == $valor) {
                                $selected = "selected";
                            } else {
                                $selected = "";
                            }
                            ?>
                            <option value="<?php echo $valor ?>" <?php echo $selected ?> ><?php echo $opcion ?></option>
                        <?php endforeach; ?>
                    </select>
                    <div style="display: none" id="error_<?php echo $name ?>"><? echo $mensaje; ?></div>
                    <?php
                }

                function crearChecks($areas) {
                    ?> 
                    <h1>Selecciona las Areas Correspondientes</h1>  
                    <table style="width: 80%" class="tabla borde redondeado" >         
                        <tr>
                            <?php
                            $i = 1;

                            foreach ($areas as $valor => $opcion) {
                                ?> 
                                <?php if ($i % 3 == 0) {
                                    ?>                         
                                    <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$opcion" ?></th>  

                                </tr>  
                                <tr>
                                    <?php
                                    $i++;
                                } else {
                                    ?>
                                    <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$opcion" ?></th>
                                    <?php
                                    $i++;
                                }
                            }
                            ?>

                    </table>
                    <div id="mensajeErrorCheck" style="display: none">
                        Debe seleccionar alguna opcion
                    </div>
                    <?php
                    /**
                      $i = 0;
                      $i++;
                      $var = current($areas);
                      while (true) {
                      ?>
                      <tr>
                      <th style="width: 33%" ><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      if ($var != false) {
                      $i++;
                      ?>
                      <th style="width: 33%"><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      if ($var != false) {
                      $i++;
                      ?>
                      <th style="width: 33%"><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      $i++;
                      if ($var == false) {
                      break;
                      }
                      ?>

                      <?php
                      } else {

                      break;
                      }
                      } else {
                      break;
                      }
                      ?>
                      </tr>

                      <?php }
                      ?>
                      </table>
                      <div id="mensajeErrorCheck" style="display: none">
                      Debe seleccionar alguna opcion
                      </div>
                     * */
                }

                function crearChecksLleno($areas, $llenos) {
                    ?> 
                    <h1>Selecciona las Areas Correspondientes</h1>  
                    <table style="width: 80%" class="tabla borde redondeado" >         
                        <tr>
                            <?php
                            $i = 1;

                            foreach ($areas as $valor => $opcion) {
                                ?> 
                                <?php
                                if ($i % 3 == 0) {

                                    if (in_array($valor, $llenos)) {
                                        ?>                    
                                        <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" checked="true"><?php echo "$opcion" ?></th>  
                                    </tr>  
                                    <tr>
                                    <?php } else { ?>

                                        <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$opcion" ?></th>  
                                    </tr>  
                                    <tr>

                                    <?php } ?>


                                    <?php
                                    $i++;
                                } else {

                                    if (in_array($valor, $llenos)) {
                                        ?>
                                        <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" checked="true"><?php echo "$opcion" ?></th>
                                        <?php
                                    } else {
                                        ?>
                                        <th style="width: 33%" ><input value="<?php echo "$valor" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$opcion" ?></th>
                                        <?php
                                    }
                                    $i++;
                                }
                            }
                            ?>

                    </table>
                    <div id="mensajeErrorCheck" style="display: none">
                        Debe seleccionar alguna opcion
                    </div>
                    <?php
                    /**
                      $i = 0;
                      $i++;
                      $var = current($areas);
                      while (true) {
                      ?>
                      <tr>
                      <th style="width: 33%" ><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      if ($var != false) {
                      $i++;
                      ?>
                      <th style="width: 33%"><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      if ($var != false) {
                      $i++;
                      ?>
                      <th style="width: 33%"><input value="<?php echo "$var" ?>" id="<?php echo "c$i" ?>" name="<?php echo "Area[]" ?> " type="checkbox" ><?php echo "$var" ?></th>
                      <?php
                      $var = next($areas);
                      $i++;
                      if ($var == false) {
                      break;
                      }
                      ?>

                      <?php
                      } else {

                      break;
                      }
                      } else {
                      break;
                      }
                      ?>
                      </tr>

                      <?php }
                      ?>
                      </table>
                      <div id="mensajeErrorCheck" style="display: none">
                      Debe seleccionar alguna opcion
                      </div>
                     * */
                }

                /*
                 * Crea input tipo reset para ser usado en formulario
                 */

                function crearReset($mensaje = "", $class_input = "", $id = "") {
                    ?>
                    <input id="<?php echo $id ?>"  type="reset" value="<?php echo $mensaje ?>" class="<?php echo $class_input ?>" />
                    <?php
                }

                function crearResetB($mensaje = "", $class_input = "", $id = "") {
                    ?>
                    <button id="<?php echo $id ?>"  type="reset" value="<?php echo $mensaje ?>" class="<?php echo $class_input ?>" />
                    <?php
                }

                function crearLabel($label, $name, $class_label = "") {
                    ?>
                    <label for="<?php echo $name ?>" class="<?php echo $class_label ?>" ><?php echo $label ?></label>
                    <?php
                }

                /*
                 * Crea input tipo submit para ser usado en formulario
                 */

                function crearSubmit($mensaje = "", $class_input = "", $i = "") {
                    ?>
                    <input id="<?php echo $i ?>" type="submit" value="<?php echo $mensaje ?>" class="<?php echo $class_input ?>"  name="<?php echo $i ?>" />
                    <?php
                    //onmouseover="javascript:ensima(<?php echo "'$validacion'" 
                }

            }
            ?>